package pe.gob.osinergmin.activity.generic;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import pe.gob.osinergmin.R;
import pe.gob.osinergmin.service.OrdenPedidoService;
import pe.gob.osinergmin.service.ProductoService;
import pe.gob.osinergmin.service.impl.OrdenPedidoServiceImpl;
import pe.gob.osinergmin.service.impl.ProductoServiceImpl;

public abstract class GenericDialog extends Dialog {

    private ProductoService productoService;

    private OrdenPedidoService ordenPedidoService;

    public GenericDialog(Context context) {
        super(context);
        productoService = ProductoServiceImpl.getInstance();
        ordenPedidoService = OrdenPedidoServiceImpl.getInstance();
    }

    public void makeText(Context context, int res_id, int duration){
        makeText(context, context.getResources().getString(res_id), duration);
    }

    public void makeText(Context context, CharSequence text, int duration){
        LayoutInflater inflater = getLayoutInflater();

        View custom_toast = inflater.inflate(R.layout.toast_custom, null);

        TextView textView = (TextView)custom_toast.findViewById(R.id.toast_text);
        textView.setText(text);

        Toast toast = new Toast(getContext().getApplicationContext());
        toast.setView(custom_toast);
        toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(duration);
        toast.show();
    }

    public ProductoService getProductoService(){
        return productoService;
    }

    public OrdenPedidoService getOrdenPedidoService(){
        return ordenPedidoService;
    }
}
